package com.example.barcodeapp.ui.own.activity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.barcodeapp.R;
import com.example.barcodeapp.adapter.AdapterXilei3;
import com.example.barcodeapp.ui.own.bean.zhifufangshiBean;

import java.util.ArrayList;

public class zhifufangshiAdapter extends RecyclerView.Adapter<zhifufangshiAdapter.ViewHolder> {
    Context context;
    ArrayList<zhifufangshiBean> list;


    private zhifufangshiAdapter.IClick callback;

    public void setCallback(IClick callback) {
        this.callback = callback;
    }

    public zhifufangshiAdapter(Context context, ArrayList<zhifufangshiBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.adapter_zhifufangshi, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.imageView12.setImageResource(list.get(position).getTupian());
        holder.textView35.setText(list.get(position).getName());
        if (list.get(position).isFangshi()) {
            holder.xuanzefangshi.setImageResource(R.drawable.xuanzhong);
        } else {
            holder.xuanzefangshi.setImageResource(R.drawable.weixuanzhong);
        }
        holder.xuanzefangshi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callback.click(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView12;
        private TextView textView35;
        private ImageView xuanzefangshi;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);

            imageView12 = (ImageView) itemView.findViewById(R.id.imageView12);
            textView35 = (TextView) itemView.findViewById(R.id.textView35);
            xuanzefangshi = (ImageView) itemView.findViewById(R.id.xuanzefangshi);
        }
    }
    public interface IClick{
        void click(int pos);
    }
}
